package programmercarl.链表.C5;

class ListNode{
    int val;
    ListNode next;
    ListNode(){}
    ListNode(int val){this.val = val;}
    ListNode(int val,ListNode next){
        this.val = val;
        this.next = next;
    }
}

class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode cur = dummy;
        ListNode node1=null,node2=null,temp=null;
        while (cur.next != null && cur.next.next != null) {
            temp=cur.next.next.next;
            node1 = cur.next;
            node2 = cur.next.next;
            cur.next = node2;
            node2.next = node1;
            node1.next = temp;
            cur=node1;
        }
        return dummy.next;
    }
}